package today.rocky.boot.eureka.config;

import com.netflix.loadbalancer.*;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @author Rocky
 * @version 1.0
 * @date 2020/3/3 18:16
 */
@Configuration
public class LoadBalanceConfig {

    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        //默认轮询
        return new RestTemplate();
    }


    @Bean
    public IRule myRule(){
        //轮询
        IRule rule = new RoundRobinRule();
//        //随机
//        IRule rule = new RandomRule();
//        //可用过滤-筛选掉断路服务和超过连接阈值的服务，再轮询
//        IRule rule = new AvailabilityFilteringRule();
//        //权重响应--根据平均时间计算服务权重，权重越大被选中概率越高
//        IRule rule = new WeightedResponseTimeRule();
//        //先轮询，如果失败再重试
//        IRule rule = new RetryRule();
//        //筛掉故障服务，选择并发最小的
//        IRule rule = new BestAvailableRule();
//        //默认---符合判断server所在区域的性能和可用性
//        IRule rule = new ZoneAvoidanceRule();

      return rule;
    }
}
